import Vue from "vue";
import Router from "vue-router";
import Login from "../views/Login.vue";
import DashBoard from "../views/DashBoard.vue";
import Register from "../views/Register.vue";
import userManage from "../views/admin/index.vue";
import studentAdd from "../views/admin/add.vue";
import pwdReset from "../views/admin/pwdReset.vue";
import Course from "../views/course/index.vue";
import Teacher from "../views/teacher/index.vue";
import Class from "../views/class/index.vue";
// import Test from "../views/Login/index.vue";
Vue.use(Router);
//获取原型对象上的push函数
const originalPush = Router.prototype.push;
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};
export default new Router({
  mode: "history",
  routes: [
    // {
    //   path: "/test",
    //   name: "test",
    //   component: Test
    // },
    {
      path: "/",
      name: "Index",
      redirect: { name: "login" }
    },
    {
      path: "/login",
      name: "login",
      component: Login
    },
    {
      path: "/register",
      name: "register",
      component: Register
    },
    {
      path: "/dashboard",
      name: "dashboard",
      component: DashBoard,
      children: [
        {
          path: "admin",
          name: "admin",
          component: userManage
        },
        {
          path: "pwdReset",
          name: "pwdReset",
          component: pwdReset
        },
        {
          path: "course",
          name: "course",
          component: Course
        },
        {
          path: "teacher",
          name: "teacher",
          component: Teacher
        },
        {
          path: "class",
          name: "class",
          component: Class
        }
      ]
    }
  ]
});
